package com.zui.entity.product;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.struts2.json.annotations.JSON;

import com.zui.entity.BaseAutoIdEntity;

@Entity
// product, filename唯一性；
@Table(name = "product_image", uniqueConstraints = { @UniqueConstraint(name = "uc_product_image", columnNames = {
		"productId", "imageId","fromDate" }) })
public class ProductImage extends BaseAutoIdEntity {
	private static final long serialVersionUID = 1L;
	public ProductImage() {
	}
	public ProductImage(Image image) {
		this.image = image;
	}
	private Product product;
	private Image image;
	
	private Date fromDate;
	private Date thruDate;
	private Integer sequenceNum;
	private String primaryFlag;

	/*------------------------------
	 * getters and annotations
	 --------------------------------*/
	@ManyToOne()
	@JoinColumn(name = "productId")
	@JSON(serialize = false)
	public Product getProduct() {
		return product;
	}
	/**
	 * Is CascadeType.ALL is set, image record will be updated to null only id is left.
	 * @return
	 */
	@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
	@JoinColumn(name = "imageId")
	public Image getImage() {
		return image;
	}
	@Column(length=1)
	public String getPrimaryFlag() {return primaryFlag;	}
	public Date getFromDate() {
		return fromDate;
	}
	public Date getThruDate() {
		return thruDate;
	}
	public Integer getSequenceNum() {
		return sequenceNum;
	}




	public void setImage(Image image) {
		this.image = image;
	}

	public void setPrimaryFlag(String primaryFlag) {
		this.primaryFlag = primaryFlag;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}
	public void setThruDate(Date thruDate) {
		this.thruDate = thruDate;
	}
	public void setSequenceNum(Integer sequenceNum) {
		this.sequenceNum = sequenceNum;
	}
}
